package cn.itlaobing.web.servlet;


import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.itlaobing.web.annotation.RequestAnnocation;
import cn.itlaobing.web.exception.MyeEXception;
import cn.itlaobing.web.model.UserModel;
import cn.itlaobing.web.service.UserService;

/** 
 * ClassName: webServlet <br/> 
 * Function:增删改查的servlet方法<br/> 
 * date: 2017年10月31日 下午7:30:06 <br/> 
 * 
 * @author 吕正强 
 * @version  
 * @since JDK 1.8 
 */
@WebServlet(value="/servlet/*",loadOnStartup=1)
public class webServlet extends BaseServlet{
	
	@RequestAnnocation("/index")
	public void index(HttpServletRequest request,HttpServletResponse response) {		
		try {
			request.getRequestDispatcher("/WEB-INF/views/userRegister.jsp").forward(request, response);
		} catch (ServletException | IOException e) {
			e.printStackTrace();
		}
	}
	/** 
	 * regist:(查询用户). <br/>
	 * 
	 * @author yan  
	 * @throws IOException 
	 * @throws ServletException 
	 * @throws MyeEXception 
	 * @since JDK 1.8 
	 */  
	@RequestAnnocation("/regection")
	public void regection(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		String account=request.getParameter("account");
		String pwd=request.getParameter("pwd");
		System.out.println(account);
		System.out.println(pwd);
		UserService us=new UserService();
		UserModel um=null;
		try {
			um=us.queryOne(account,pwd);
			if(um==null) {
				request.getRequestDispatcher("/WEB-INF/views/userRegister.jsp").forward(request, response);				
			}else {
			}
		} catch (MyeEXception e) {
			e.printStackTrace();
		}
		request.getSession().setAttribute("USER",um);
		request.getRequestDispatcher("/listServlet/querymore").forward(request, response);				
	}	
}
